package com.cskaoyan.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * 创建日期: 2022/04/09 11:53
 *
 * @author HanWeiqi
 */
public class WxSessionManager extends DefaultWebSessionManager {

    //保证认证前后session不发生变化的方法
    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        //获得之前的sessionId
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String sessionId = httpServletRequest.getHeader("X-CskaoyanMarket-Token");
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }

        return super.getSessionId(request, response);
    }
}
